//
//  TZNavigationController.m
//  BSBDJ
//
//  Created by user on 16/5/23.
//  Copyright © 2016年 Burning. All rights reserved.
//

#import "TZNavigationController.h"

@interface TZNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation TZNavigationController
/*
  <UIScreenEdgePanGestureRecognizer: 0x79a683d0; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x79a668c0>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x79a69540>)>>
 */
#pragma mark 如果点击返回 导航条有渲染 最边上又一层黑色的 需要给导航条加背景图片
+ (void)load
{
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:self, nil];

    [bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    pan.delegate = self;
    self.interactivePopGestureRecognizer.enabled = NO;
    [self.view addGestureRecognizer:pan];

}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return self.childViewControllers.count > 1;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0){
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIButton *backBtn = [UIButton new];
        [backBtn setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:0];
        [backBtn setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateSelected];
        [backBtn sizeToFit];
        [backBtn addTarget:self action:@selector(clickBackBtn) forControlEvents:UIControlEventTouchUpInside];
        UIView *backView = [UIView new];
        backView.bounds = backBtn.bounds;
        [backView addSubview:backBtn];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backView];
    }
    
    
    [super pushViewController:viewController animated:animated];
}

- (void)clickBackBtn
{
    [self popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
